home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Optimization Q: for( i=0; i<SIZE/2; i++) ??
- Date: Tue, 20 Feb 96 22:18:32 GMT
- Organization: none
- Message-ID: <824854712snz@genesis.demon.co.uk>
- References: <4g1j9n$ooe@news.csus.edu> <Dn2nKB.C1@uns.bris.ac.uk>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <Dn2nKB.C1@uns.bris.ac.uk>
- nathan@pact.srf.ac.uk "Nathan Sidwell" writes:
-
- >Jerry Leong (wleong@sfsu.edu) wrote:
- >
- >: This question has been bothering me for quite a while now.
- >
- >: If I have the following for loop,
- >: for( i=0; i< SIZE/2 ; i++).....
- >: Will the code execute faster if I precompute SIZE/2 before hand and
- >: do this
- >: k = SIZE/2;
- >: for(i=0; i<k ; i++).....
-
- ...
-
- >Now, writing the loop as
- >for(ix = SIZE/2; ix--;)
- > ...
- >might make a (small) difference.
-
- Like making the loop variable take on the values (within the loop body) of
- SIZE/2 down to 1 rather than 0 up to SIZE/2-1. :-)
-
- If the variable is just used as an iteration count and its value is not
- important then this is fine but the compiler can probably make this
- optimisation itself in that case (I've seen it done).
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-